<template>
	<view>
		<view class="address-choose-box" v-if="Object.keys(address).length === 0">
			<button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址+</button>
		</view>
		<view class="address-info-box" v-else>
			<view class="row-top">
				<view class="row-top-left">收货人：{{address.userName}}</view>
				<view class="row-top-right">电话：{{address.telNumber}}
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<view class="row-bottom">
				<view class="row-bottom-left">收获地址:</view>
				<view class="row-bottom-right">{{addressStr}}</view>
			</view> 
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations,mapGetters } from 'vuex'
	export default {
		name:"my-address",
		data() {
			return {
				
			};
		},
		computed: {
			...mapState('my_user',['address']),
			...mapGetters('my_user',['addressStr'])
			// addressStr() {
			// 	return this.address.provinceName + this.address.cityName + this.address.countyName + this.address.detailInfo
			// }
		},
		methods: {
			...mapMutations('my_user',['updateAddress']),
			async chooseAddress() {
				// 调用微信提供的一个地址渲染api
				const [err,succ] = await uni.chooseAddress()
				if (err === null && succ.errMsg === 'chooseAddress:ok') {
					this.updateAddress(succ)
				}
			},
		}
	}
</script>

<style lang="scss">
.address-choose-box {
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 15px 0;
}
.address-info-box {
	font-size: 12px;
	padding: 0 5px;
	height: 90px;
	display: flex;
	flex-direction: column;
	justify-content: center;
	.row-top {
		display: flex;
		justify-content: space-between;
		.row-top-right {
			display: flex;
			align-items: center;
		}
	}
	.row-bottom {
		display: flex;
		align-items: center;
		margin-top: 10px;
	}
}
</style>
